home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / term-source.lha / Extras / Source / term-Source.lha / TimePanel.c < prev    next >
C/C++ Source or Header  |  1995-02-07  |  3KB  |  171 lines

  1. /*
  2. **    TimePanel.c
  3. **
  4. **    Editing panel for time values
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_USE=1,GAD_CANCEL };
  13.  
  14. STATIC LONG __saveds
  15. ShowTime(struct Gadget *SomeGadget,WORD Level)
  16. {
  17.     STATIC UBYTE Buffer[40];
  18.  
  19.     FormatTime(Buffer,Level / 6,(Level % 6) * 10,-1);
  20.  
  21.     return((LONG)Buffer);
  22. }
  23.  
  24. BYTE __regargs
  25. TimePanel(UBYTE *StartTime)
  26. {
  27.     struct LayoutHandle    *Handle;
  28.     BYTE             Result = FALSE;
  29.     UBYTE             Time = *StartTime;
  30.  
  31.     if(Handle = LT_CreateHandleTags(Window -> WScreen,
  32.         LH_LocaleHook,    &LocaleHook,
  33.     TAG_DONE))
  34.     {
  35.         struct Window *PanelWindow;
  36.  
  37.         LT_New(Handle,
  38.             LA_Type,    VERTICAL_KIND,
  39.         TAG_DONE);
  40.         {
  41.             LT_New(Handle,
  42.                 LA_Type,    VERTICAL_KIND,
  43.                 LA_LabelID,    MSG_V36_1507,
  44.             TAG_DONE);
  45.             {
  46.                 LT_New(Handle,
  47.                     LA_Type,        SliderType,
  48.                     LA_LabelID,        MSG_TIMEPANEL_TIME_GAD,
  49.                     LA_Chars,        15,
  50.                     LA_UBYTE,        &Time,
  51.                     GTSL_Min,        DT_GET_TIME( 0, 0),
  52.                     GTSL_Max,        DT_GET_TIME(23,50),
  53.                     GTSL_DispFunc,        ShowTime,
  54.                     GTSL_LevelFormat,    "%s",
  55.                 TAG_DONE);
  56.  
  57.                 LT_EndGroup(Handle);
  58.             }
  59.  
  60.             LT_New(Handle,
  61.                 LA_Type,VERTICAL_KIND,
  62.             TAG_DONE);
  63.             {
  64.                 LT_New(Handle,
  65.                     LA_Type,    XBAR_KIND,
  66.                     LAXB_FullSize,    TRUE,
  67.                 TAG_DONE);
  68.  
  69.                 LT_EndGroup(Handle);
  70.             }
  71.  
  72.             LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  73.                 LAGR_SameSize,    TRUE,
  74.                 LAGR_Spread,    TRUE,
  75.             TAG_DONE);
  76.             {
  77.                 LT_New(Handle,
  78.                     LA_Type,    BUTTON_KIND,
  79.                     LA_LabelID,    MSG_GLOBAL_USE_GAD,
  80.                     LA_ID,        GAD_USE,
  81.                     LABT_ReturnKey,    TRUE,
  82.                     LABT_ExtraFat,    TRUE,
  83.                 TAG_DONE);
  84.  
  85.                 LT_New(Handle,
  86.                     LA_Type,    BUTTON_KIND,
  87.                     LA_LabelID,    MSG_GLOBAL_CANCEL_GAD,
  88.                     LA_ID,        GAD_CANCEL,
  89.                     LABT_EscKey,    TRUE,
  90.                     LABT_ExtraFat,    TRUE,
  91.                 TAG_DONE);
  92.  
  93.                 LT_EndGroup(Handle);
  94.             }
  95.  
  96.             LT_EndGroup(Handle);
  97.         }
  98.  
  99.         if(PanelWindow = LT_Layout(Handle,LocaleString(MSG_TIMEPANEL_SET_TIME_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
  100.             LAWN_HelpHook,        &GuideHook,
  101.             LAWN_Parent,        Window,
  102.             WA_DepthGadget,        TRUE,
  103.             WA_CloseGadget,        TRUE,
  104.             WA_DragBar,        TRUE,
  105.             WA_RMBTrap,        TRUE,
  106.             WA_Activate,        TRUE,
  107.         TAG_DONE))
  108.         {
  109.             struct IntuiMessage    *Message;
  110.             BOOLEAN             Done = FALSE;
  111.             ULONG             MsgClass,
  112.                          MsgQualifier;
  113.             UWORD             MsgCode;
  114.             struct Gadget        *MsgGadget;
  115.  
  116.             GuideContext(CONTEXT_DAY);
  117.  
  118.             LT_ShowWindow(Handle,TRUE);
  119.  
  120.             PushWindow(PanelWindow);
  121.  
  122.             do
  123.             {
  124.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  125.                     break;
  126.  
  127.                 while(Message = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort))
  128.                 {
  129.                     MsgClass    = Message -> Class;
  130.                     MsgQualifier    = Message -> Qualifier;
  131.                     MsgCode        = Message -> Code;
  132.                     MsgGadget    = (struct Gadget *)Message -> IAddress;
  133.  
  134.                     GT_ReplyIMsg(Message);
  135.  
  136.                     LT_HandleInput(Handle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
  137.  
  138.                     if(MsgClass == IDCMP_CLOSEWINDOW)
  139.                         Done = TRUE;
  140.  
  141.                     if(MsgClass == IDCMP_GADGETUP)
  142.                     {
  143.                         switch(MsgGadget -> GadgetID)
  144.                         {
  145.                             case GAD_USE:
  146.  
  147.                                 *StartTime = Time;
  148.  
  149.                                 Result = Done = TRUE;
  150.  
  151.                                 break;
  152.  
  153.                             case GAD_CANCEL:
  154.  
  155.                                 Done = TRUE;
  156.                                 break;
  157.                         }
  158.                     }
  159.                 }
  160.             }
  161.             while(!Done);
  162.  
  163.             PopWindow();
  164.         }
  165.  
  166.         LT_DeleteHandle(Handle);
  167.     }
  168.  
  169.     return(Result);
  170. }
  171.